//! # Magic Query
//!
//! Fast query data from `Vec<HashMap<K, V>>` datatype

pub mod parser;
pub mod query;

pub use parser::{Element, Junction, Node, ParseResult, Parser};
pub use query::{List, Map, MapItem, Number, QueryAble, Value};

/// reuse error type
#[derive(Debug, Clone)]
pub enum Error {
    Regex(regex::Error),
    Parse(String),
    Query(String),
}

/// create a parser result of `Query` from row code
/// # Examples
///```
/// // row code style
/// let parser = parse!([name=2]+[age=25]);
/// // or static str style
/// let parser = parse!(@str "[name=2]+[age=25]");
///```
///
#[macro_export]
macro_rules! parse {

    // use as `parse!(@str "name=2")`
    (@str $s:expr) => {{
        use std::convert::TryFrom;
        $crate::parser::Parser::try_from($s)
    }};


     // use as `parse!(name=2)`
    ($($t:tt)*) => {{
        parse!(@str stringify!($($t)*))
    }};
}
